package com.lh.dao;

import com.lh.entity.Goods;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @Author: LuoHang
 * @Date: 2021/2/10 12:26
 * @Description
 */
@Repository
public class GoodsDao {
    @Autowired
    private SqlSessionTemplate sessionTemplate;

    public Goods getGoodsById(Integer id){
        return sessionTemplate.selectOne("GoodsMapper.getGoodsById",id);
    }

    public List<Goods> getGoods(Map<String,Object> map){
        return sessionTemplate.selectList("GoodsMapper.getGoods",map);
    }

    public int getCount(Map<String,Object> map){
        return sessionTemplate.selectOne("GoodsMapper.getCount",map);
    }

    public int addGoods(Goods goods){
        return sessionTemplate.insert("GoodsMapper.addGoods",goods);
    }

    public int updateGoods(Map<String,Object> map){
        return sessionTemplate.update("GoodsMapper.updateGoods",map);
    }

    public int deleteGoodsById(Integer id){
        return sessionTemplate.delete("GoodsMapper.deleteGoodsById",id);
    }

    public int downMany(List<Integer> ids){
        return sessionTemplate.update("GoodsMapper.downMany",ids);
    }

    public int upMany(List<Integer> ids){
        return sessionTemplate.update("GoodsMapper.upMany",ids);
    }

    public int deleteGoodsByIds(List<Integer> ids){
        return sessionTemplate.delete("GoodsMapper.deleteGoodsByIds",ids);
    }

    public List<Goods> getGoodsByTime(Map<String,Object> map){
        return sessionTemplate.selectList("GoodsMapper.getGoodsByTime",map);
    }

    public int getGoodsCategoryCount(Integer categoryId){
        return sessionTemplate.selectOne("GoodsMapper.getGoodsCategoryCount",categoryId);
    }

    public Goods getGoodsAdd(Integer userId){
        return sessionTemplate.selectOne("GoodsMapper.getGoodsAdd",userId);
    }
}
